﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 考勤数据处理软件
{
    class Work
    {

        public static double eps = 0.001;

        private static double convert_string_to_double(string str)
        {
            if (str == "")
            {
                return 0;
            }
            str = str.Replace("*", "").Trim();
            string[] s = str.Split(':');
            if (s.Length == 2)
            {
                int a = Convert.ToInt32(s[0]);
                int b = Convert.ToInt32(s[1]);
                double ans = (double)a + (double)b / 60;
                return ans;
            }
            else
            {
                return 0;
            }
        }

        public static double work_time_one(string start, string end)
        {
            double s = convert_string_to_double(start);
            double e = convert_string_to_double(end);
            if (s + e < eps)
            {
                return 0.00;
            }
            if (s < eps) s = 8.5;
            if (e < eps) e = 12;
            if (s < 8.5 && s > eps) s = 8.5;
            if (e > 12.0) e = 12;
            return work_time(s,e);
        }
        public static double work_time_two(string start, string end)
        {
            double s = convert_string_to_double(start);
            double e = convert_string_to_double(end);
            if (s + e < eps)
            {
                return 0.00;
            }
            if (s < eps) s = 14.5;
            if (e < eps) e = 18;
            if (s < 15.0 && s >= eps) s = 14.5;
            if (e > 18.0) e = 18.0;
            return work_time(s, e);
        }
        public static double work_time_thr(string start, string end)
        {
            double s = convert_string_to_double(start);
            double e = convert_string_to_double(end);
            if (s + e < eps)
            {
                return 0.00;
            }
            if (s < eps) s = 19;
            if (e < eps) e = 21.5;
            if (s < 19.0 && s >= eps) s = 19.0;
            if (e > 21.5) e = 21.5;
            return work_time(s, e);
        }


        public static double work_time(double start, double end)
        {
            return end - start;
        }
    }
}
